<?php
	#############################################################################################
	# Programmer: สมบูรณ์  กองลี																#
	# Email		: hugo8xx@hotmail.com.															#
	#############################################################################################

	AclCC($_SERVER['REDIRECT_URL']);

	$header_tp		= new template('views/_template/header.html');
	$header_date	= date(DATE_RFC822);
	$header_last	= last_login($ss_user_id, $_SERVER['REMOTE_ADDR']);
	$header_title 	= "Star Fashion Backoffice";
	
	$sql = "SELECT * FROM `control_acl` INNER JOIN `control_mod` ON `control_acl`.`mod_id` = `control_mod`.`mod_id` WHERE `control_acl`.`user_id` = '$ss_user_id' ORDER BY `control_mod`.`order`";
	$query = mysql_query($sql);
	$header_tp->block('result');
	while($result = mysql_fetch_assoc($query)) {
		$name	= $result['name'];
		$url	= $result['url'];
		$header_tp->apply();
	}
	mysql_free_result($query);

	$header_html	= _u($header_tp->generate(), 'header');

	$footer_tp = new template('views/_template/footer.html');
	$footer_html = _u($footer_tp->generate(), 'footer');
	
	$fix_ie = <<<HTML
<!--[if lt IE 9]>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<script type="text/javascript" src="/scripts/IE9.js"></script>
<![endif]-->
HTML;
	$fix_ie = _u($fix_ie, 'IE');
	$fix_ie	= "";

	function last_login($user_id) {
		$sql	= "SELECT `ip`, `ipx`, `date` FROM `control_log` WHERE `user_id` = '$user_id' AND `action` ='/login'  ORDER BY `date` DESC LIMIT 1";
		$query	= mysql_query($sql);

		$last_login = '';
		while($result = mysql_fetch_assoc($query)) {
			$last_login = 'IP: '. $result['ip']. ($result['ipx'] ? ':'.$result['ipx'] : '').' on '. formatDate($result['date'], DATE_RFC822);
		}
		mysql_free_result($query);
		return $last_login;
	}
?>